package com.example.crm_system.service.impl;

import com.example.crm_system.entity.Business;
import com.example.crm_system.entity.Params;
import com.example.crm_system.mapper.BusinessMapper;
import com.example.crm_system.service.BusinessService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {

    @Resource
    private BusinessMapper businessMapper;

    @Override
    public void insert(Business business){ businessMapper.insert(business); }

    @Override
    public void update(Business business){ businessMapper.update(business); }

    @Override
    public void delete(Integer bno) { businessMapper.delete(bno); }

    @Override
    public List<Business> selectAll() { return businessMapper.selectAll(); }

    @Override
    public List<Business> selectByBno(Integer bno) { return businessMapper.selectByBno(bno); }

    @Override
    public PageInfo<Business> searchBusiness(Params params) {
        // 开启分页查询功能
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        // 接下来的查询会自动按照当前开启的分页设置来查询
        List<Business> list = businessMapper.searchBusiness(params);
        return PageInfo.of(list);
    }
}
